//------------------------------------------------------------------------
// Abstract: Define of class XString
//
// Authoring: XiaoHanxiong
//
// Time: 2014.03.21
//
// Static test:
//
// Version history:
//		Ver_1.0 : 2014.03.21	XiaoHanxiong
//------------------------------------------------------------------------
#ifndef _Library_XString_h_
#define _Library_XString_h_

#include "stdafx.h"

namespace Library
{
	enum _LIBRARY Notation
	{
		Bin = 2,
		Oct = 8,
		Dec = 10,
		Hex = 16
	};

	class _LIBRARY XString
	{
	private:
		// Constructor
		XString();
		// Destructor
		~XString();

	/* Operation on alphabet/number */
	public:
		// Lower/Upper case
		static void LowerA(string& str);
		static void LowerA(char ch);
		static void UpperA(string& str);
		static void UpperA(char ch);
		static void LowerW(wstring& str);
		static void LowerW(wchar_t ch);
		static void UpperW(wstring& str);
		static void UpperW(wchar_t ch);
		// Format string
		static void FormatA(string& str, const char* format, ...);
		static void FormatW(wstring& str, const wchar_t* format, ...);
		// Is alphabet/number
		static bool IsAlphaA(const string& str);
		static bool IsAlphaA(const char ch);
		static bool IsNumberA(const string& str);
		static bool IsNumberA(const char ch);
		static bool IsAlphaW(const wstring& str);
		static bool IsAlphaW(const wchar_t ch);
		static bool IsNumberW(const wstring& str);
		static bool IsNumberW(const wchar_t ch);


	/* Number ==> String */
	public:
		// Number ==> Binary String
		static void NumToBinStringA(unsigned short in, string& str);
		static void NumToBinStringA(unsigned int in, string& str);
		static void NumToBinStringA(unsigned __int64 in, string& str);
		static void NumToBinStringW(unsigned short in, wstring& str);
		static void NumToBinStringW(unsigned int in, wstring& str);
		static void NumToBinStringW(unsigned __int64 in, wstring& str);
		// Number ==> Dec String
		static void NumToDecStringA(unsigned short in, string& str);
		static void NumToDecStringA(unsigned int in, string& str);
		static void NumToDecStringA(unsigned __int64 in, string& str);
		static void NumToDecStringA(float in, string& str);//???
		static void NumToDecStringA(double in, string& str);//???
		static void NumToDecStringW(unsigned short in, wstring& str);
		static void NumToDecStringW(unsigned int in, wstring& str);
		static void NumToDecStringW(unsigned __int64 in, wstring& str);
		static void NumToDecStringW(float in, wstring& str);
		static void NumToDecStringW(double in, wstring& str);
		// Number ==> Octal String
		static void NumToOctStringA(unsigned short in, string& str);
		static void NumToOctStringA(unsigned int in, string& str);
		static void NumToOctStringA(unsigned __int64 in, string& str);
		static void NumToOctStringW(unsigned short in, wstring& str);
		static void NumToOctStringW(unsigned int in, wstring& str);
		static void NumToOctStringW(unsigned __int64 in, wstring& str);
		// Number ==> Hex String
		static void NumToHexStringA(unsigned short in, string& str);
		static void NumToHexStringA(unsigned int in, string& str);
		static void NumToHexStringA(unsigned __int64 in, string& str);
		static void NumToHexStringW(unsigned short in, wstring& str);
		static void NumToHexStringW(unsigned int in, wstring& str);
		static void NumToHexStringW(unsigned __int64 in, wstring& str);


	/* String ==> Number */	
	public:
		// Binary String ==> Number
		static void BinStringToNumA(string& str, short& out);
		static void BinStringToNumA(string& str, unsigned short& out);
		static void BinStringToNumA(string& str, int& out);
		static void BinStringToNumA(string& str, unsigned int& out);
		static void BinStringToNumA(string& str, __int64& out);
		static void BinStringToNumA(string& str, unsigned __int64& out);
		static void BinStringToNumW(wstring& str, short& out);
		static void BinStringToNumW(wstring& str, unsigned short& out);
		static void BinStringToNumW(wstring& str, int& out);
		static void BinStringToNumW(wstring& str, unsigned int& out);
		static void BinStringToNumW(wstring& str, __int64& out);
		static void BinStringToNumW(wstring& str, unsigned __int64& out);
		// Octal String ==> Number
		static void OctStringToNumA(string& str, short& out);
		static void OctStringToNumA(string& str, unsigned short& out);
		static void OctStringToNumA(string& str, int& out);
		static void OctStringToNumA(string& str, unsigned int& out);
		static void OctStringToNumA(string& str, __int64& out);
		static void OctStringToNumA(string& str, unsigned __int64& out);
		static void OctStringToNumW(wstring& str, short& out);
		static void OctStringToNumW(wstring& str, unsigned short& out);
		static void OctStringToNumW(wstring& str, int& out);
		static void OctStringToNumW(wstring& str, unsigned int& out);
		static void OctStringToNumW(wstring& str, __int64& out);
		static void OctStringToNumW(wstring& str, unsigned __int64& out);
		// Dec String ==> Number
		static void DecStringToNumA(string& str, short& out);
		static void DecStringToNumA(string& str, unsigned short& out);
		static void DecStringToNumA(string& str, int& out);
		static void DecStringToNumA(string& str, unsigned int& out);
		static void DecStringToNumA(string& str, __int64& out);
		static void DecStringToNumA(string& str, unsigned __int64& out);
		static void DecStringToNumW(wstring& str, short& out);
		static void DecStringToNumW(wstring& str, unsigned short& out);
		static void DecStringToNumW(wstring& str, int& out);
		static void DecStringToNumW(wstring& str, unsigned int& out);
		static void DecStringToNumW(wstring& str, __int64& out);
		static void DecStringToNumW(wstring& str, unsigned __int64& out);
		// Hex String ==> Number
		static void HexStringToNumA(string& str, short& out);
		static void HexStringToNumA(string& str, unsigned short& out);
		static void HexStringToNumA(string& str, int& out);
		static void HexStringToNumA(string& str, unsigned int& out);
		static void HexStringToNumA(string& str, __int64& out);
		static void HexStringToNumA(string& str, unsigned __int64& out);
		static void HexStringToNumW(wstring& str, short& out);
		static void HexStringToNumW(wstring& str, unsigned short& out);
		static void HexStringToNumW(wstring& str, int& out);
		static void HexStringToNumW(wstring& str, unsigned int& out);
		static void HexStringToNumW(wstring& str, __int64& out);
		static void HexStringToNumW(wstring& str, unsigned __int64& out);

	public:
		// Float/Double String ==> Number
		static void FloatStringToNumA(string& str, float& out);
		static void FloatStringToNumW(wstring& str, float& out);
		static void DoubleStringToNumA(string& str, double& out);
		static void DoubleStringToNumW(wstring& str, double& out);
		// Number ==> Float/Double String
		static void NumToFloatStringA(float in, string& str);
		static void NumToFloatStringW(float in, wstring& str);
		static void NumToDoubleStringA(double in, string& str);
		static void NumToDoubleStringW(double in, wstring& str);

	/* Convert between Wide Char and Multi Char */
	public:
		static void ConvertChar_MultiToWide(string& in, wstring& out);
		static void ConvertChar_WideToMulti(wstring& in, string& out);

	/* Trim a string */
	public:
		// Trim a string to remain number, alphabet, underline
		static void TrimA(string& str);
		static void TrimW(wstring& str);
		// Trim a string to remain/exclude the character in vector
		static void TrimReA(string& str, string& remain);
		static void TrimExA(string& str, string& exclude);
		static void TrimReW(wstring& str, wstring& remain);
		static void TrimExW(wstring& str, wstring& exclude);
		// Replace the string by specify
		static void ReplaceA(string& str, string& replace, string& specify);
		static void ReplaceW(wstring& str, wstring& replace, wstring& specify);

	/* Split a string according to the splitter */
	public:
		static void SplitA(string& in, vector<string>& out, char splitter);
		static void SplitW(wstring& in, vector<wstring>& out, wchar_t splitter);
		static void SplitA(string& in, vector<string>& out, char splitter, char outer);
		static void SplitW(wstring& in, vector<wstring>& out, wchar_t splitter, wchar_t outer);

	/* Convert UTF-8 encoding string to normal string */
	#if defined(WIN32) && defined(_WINNLS_) // Windows APIs header
	public:
		static void UTF8ToNormalA(void* ptr, size_t size, string& str);
		static void UTF8ToNormalW(void* ptr, size_t size, wstring& str);
	#endif // defined(WIN32) && defined(_WINNLS_)
	};

}// _Library_

#endif
